package com.lhd.task;

import com.lhd.entity.enums.RecordStatusEnum;
import com.lhd.entity.po.Record;
import com.lhd.entity.query.RecordQuery;
import com.lhd.service.RecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author: liuhd
 * @Date: 2025/5/6 12:52
 * @Description: 定时任务处理器，用于定期修改记录状态
 */
@Component
@Slf4j
public class MyTaskExecutor {

    @Resource
    private RecordService recordService;

    /**
     * 每隔 10 秒执行一次
     */
    @Scheduled(fixedRate = 10_000) // 单位是毫秒
    public void modifyRecordStatus() {
        try {
            log.info("任务处理器执行修改状态方法！！");

            RecordQuery recordQuery = new RecordQuery();
            recordQuery.setModifyRecordStatus(true);
            recordQuery.setStatus(RecordStatusEnum.TODO_LEAVE.getCode());

            Record record = new Record();
            record.setStatus(RecordStatusEnum.ABSENT.getCode());

            recordService.updateByQuery(record, recordQuery);

        } catch (Exception e) {
            log.error("任务处理器修改状态时出现异常", e);
        }
    }
}